home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / general.programming / comp.programming_1572_000022.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  1.6 KB  |  39 lines

  1. Newsgroups: comp.programming
  2. Path: dd.chalmers.se!news.chalmers.se!sunic!EU.net!howland.reston.ans.net!torn!newshub.ccs.yorku.ca!oz
  3. From: oz@ursa.sis.yorku.ca (Ozan S. Yigit)
  4. Subject: Re: Hash function for strings
  5. In-Reply-To: amundsj@novell.oih.no's message of 3 Mar 1994 17:39:59 GMT
  6. Message-ID: <OZ.94Mar3155416@ursa.sis.yorku.ca>
  7. Sender: news@newshub.ccs.yorku.ca (USENET News System)
  8. Organization: The Electric Skillet
  9. References: <amundsj.1.0@novell.oih.no>
  10. Date: Thu, 3 Mar 1994 20:54:16 GMT
  11. Lines: 27
  12.  
  13. AMUNDSEN JARLE/3AA/D:
  14.  
  15.    I am trying to find a good hash function for strings, names that is, and
  16.    wonder if anyone has an idea on how good such a function can hash. Given
  17.    that the keys are not known in advance.
  18.  
  19. there are several good multiplicative ones, eg.
  20.  
  21.         33      due to dan bernstein [h = (h << 5) + h + c]
  22.         131     due to gonnet/baeza-yates ("Handbook")
  23.     65599    due to me (sdbm) [h = (h << 6) + (h << 16) - h + c]
  24.  
  25. there are also a bunch of scramble-type functions, eg. peter honeyman's
  26. crc-hash routine from pathalias, or the one from lcc [str and list mgmt
  27. module]. have you looked at those?
  28.  
  29.    The function I found to be best, starts at the end of the string and 
  30.    recursively shifts the hash of the previous character n times to the left and
  31.    subtracts m, and adds the shift and subtraction of the current character.
  32.  
  33. is n a constant or the index of the current char? m is the table size?
  34.  
  35. oz
  36. ---
  37. C++ was invented because Vogon poetry | electric: oz@sis.yorku.ca
  38. wasn't destructive enough. -anonymous | ph:[416] 736 2100 x 33976
  39.